<template>
    <div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button type="primary"  class="handle-del mr10" @click="delAllSelection">批量删除</el-button> -->
                <el-form ref="form" :inline="true" :model="form">
                    <el-form-item>
                        <el-button type="primary" @click="handleAdd">新增</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
                <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->Ï

                <el-table-column width="auto" label="ID" align="center">
                    <template slot-scope="scope">{{ scope.row.id }}</template>
                </el-table-column>

                <el-table-column width="auto" label="全称" align="center">
                    <template slot-scope="scope">{{ scope.row.description }}</template>
                </el-table-column>

                <el-table-column width="auto" label="简称" align="center">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column width="auto" label="代码" align="center">
                    <template slot-scope="scope">{{ scope.row.code }}</template>
                </el-table-column>

                <el-table-column width="auto" label="状态" align="center">
                    <template slot-scope="scope">
                        <!-- <el-tag :type="scope.row.state === '成功' ? 'success' : scope.row.state === '失败' ? 'danger' : ''">
                        
                            <img style="width: 20px;height: 20px;" src="http://static.xingfeng.cool/images/success.png" alt="" />
                        </el-tag> -->

                        <img
                            v-if="scope.row.status == 1"
                            style="width: 20px;height: 20px;"
                            src="@/assets/images/歌曲管理/u464.png"
                            alt=""
                        />
                        <img
                            v-else-if="scope.row.status == 0"
                            style="width: 20px;height: 20px;"
                            src="@/assets/images/歌曲管理/u468.png"
                            alt=""
                        />
                    </template>
                </el-table-column>

                <el-table-column width="auto" label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="handleImplement(scope.$index, scope.row)">管理</el-button>
                        <!-- <el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>

            <!-- <div class="pagination">
                <el-pagination
                    background
                    layout="total,sizes, prev, pager, next, jumper"
                    :page-sizes="[5, 10, 20, 30]"
                    @size-change="handleSizeChange"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div> -->
        </div>
    </div>
</template>

<script>
import NProgress from 'nprogress';
export default {
    name: 'ChannelList',
    data() {
        return {
            query: {
                // address: '',
                // name: '',
                // pageIndex: 1,
                // pageSize: 10
            },
            tableData: [],
            pageTotal: 0,
            form: {}
        };
    },
    // created() {
    //     this.getData();
    // },
    watch: {
        $route: {
            deep: true,
            immediate: true,
            handler(a, b) {
                console.log(a, b);
                if (a.name === 'ChannelList') {
                    this.getData();
                }
            }
        }
    },
    methods: {
        async getData() {
            try {
                NProgress.start();
                let url = '/channel/query';
                let { data: res } = await this.$http[4].get(url, {
                    params: this.$removeField({
                        code: '',
                        name: '',
                        regionId: '',
                        status: ''
                    })
                });
                console.log(res);
                if (res.code != '0000') {
                    throw new Error(res.message);
                }
                if (res.data && res.data.length > 0) {
                    // res.data.map(item => {
                    //     item.createTime = this.$dateFormat(item.createTime, '', '-');
                    // });
                    this.tableData = res.data;
                    this.pageTotal = res.data.totalElements;
                } else {
                    this.tableData = [];
                    this.pageTotal = 0;
                }
                NProgress.done();
            } catch (err) {
                console.log(err);
                NProgress.done();
                this.$message.error({
                    message: err.message,
                    duration: 1500
                });
            }
        },
        // 触发搜索按钮
        handleAdd() {
            // this.$set(this.query, 'pageIndex', 1);
            // this.getData();

            this.$router.replace({
                path: '/channel/add'
                // e: '0'
            });
        },

        handleImplement(index, row) {
            this.$router.replace({
                // path: '/album_3/info_2',
                path: '/channel/add',
                query: {
                    id: row.id
                    // e: '1'
                }
            });
        }
        // 保存编辑
        // saveEdit() {
        //     this.editVisible = false;
        //     this.$message.success(`修改第 ${this.idx + 1} 行成功`);
        //     this.$set(this.tableData, this.idx, this.form);
        // },
        // 分页导航
        // handlePageChange(val) {
        //     this.$set(this.query, 'pageIndex', val);
        //     this.getData();
        // },
        // handleSizeChange(val) {
        //     this.$set(this.query, 'pageSize', val);
        //     this.getData();
        // }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    /* width: 300px; */
    width: 69px;
    height: 28px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
